package com.css.dzj.dzjportal.common.menu;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.css.aq.server.service.BaseService;
import com.css.dzj.dzjportal.common.util.R;
import com.css.dzj.dzjportal.common.util.Restful.RestfulUtil;
import com.css.dzj.dzjportal.common.util.ServiceUtil;
import com.css.dzj.dzjportal.sys.user.entity.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sys")
public class GetSysController {
    @Autowired
    private BaseService baseService;
    @Autowired
    private HttpServletRequest request;
    @Value("${BASE_URL}")
    private String BASE_URL;
    @GetMapping("/getsys")
    public R getSys(){
        HttpSession session=request.getSession();
        LoginUser userInfo = (LoginUser) session.getAttribute("_USER_LOGIN_INFO_");
        List<Map<String,Object>> sysApp1 = userInfo.getSysApp();
        List<Map<String,Object>> sysApp = new ArrayList<>();
        Map<String,Object> zfrygl = new HashMap<>();
        if (userInfo != null){
            List<String> roleList = userInfo.getRole();
            for (int i = 0; i < roleList.size(); i++) {
                if ("执法人员管理".equals(roleList.get(i))){
                    zfrygl.put("appName","执法人员管理");
                    zfrygl.put("isValid","1");
                    zfrygl.put("description","安评系统执法人员管理");
                    zfrygl.put("updateUser","c8f1ba6c7cf842409aba43206e9f7442");
                    zfrygl.put("updateTime","2020-10-27T07:48:16.000+0000");
                    zfrygl.put("appCode","1001");
                    zfrygl.put("appAddress","http://10.5.103.120:8085/dzjap?u=zfry");
                    zfrygl.put("sort","3");
                    zfrygl.put("publicKey","MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCtKG83TGwmh4J2bCfSr2Glv+uNoKiwZbeG1ckSVGOK0PrEy04kIYH11TA2/zHYXIfT5vS3IjQbUhPv4xjdrIOb6BWcDP8klrOE1AED/eE14rVD5GDnvnJFl3X9wrpIHWoAwEajfrASNJhptdaM3XYN+29874/0m5zF/biLAyZc6QIDAQAB");
                    zfrygl.put("privateKey","MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAK0obzdMbCaHgnZsJ9KvYaW/642gqLBlt4bVyRJUY4rQ+sTLTiQhgfXVMDb/Mdhch9Pm9LciNBtSE+/jGN2sg5voFZwM/ySWs4TUAQP94TXitUPkYOe+ckWXdf3CukgdagDARqN+sBI0mGm11ozddg37b3zvj/SbnMX9uIsDJlzpAgMBAAECgYAhuhd3gOYr1wcdQ9G54rk1TJ1314wj15wYojlo3ZEJ78x4WlUdCn3CwUSD4c72ooc+SeTuarYVgDYr6mLkgn6bo6Edq3OpdgldbwGfcPlgwQ7fCO8ld3VL4SvbxcLG2S3dJZRLdDyECiDs2KkALJddpxeEGiVxUZoDeQ+QkgKjUQJBAPEsluwuoXCflcCN/a+1m+lsUVxvvvN09L80lsDUOrOIMVhA3QquHZgq+6NqjAK/XJAAEi7847Lwi8xuW0sXi20CQQC3zXVsg83mL8fXXSfnwP7SIBgEdXke1/JlqtoR1MsDTq5tY249x6utwWuNqXRmAPOC4D3bMkWm92lR5fCOBM3tAkEA2cyL63VdJClqgv94F6Npzw6cF19vUcvQb5CdiDzhWlrnPS0uscN2RIKkx/qjwKNygzUdNsP5GhM0HQWYeqMjrQJAeO4ONxJVMwD23ASnj7yUK83/31cnFJsCGdAaYCcAVzG6Y7BKxQ0NMGoVCISYV9CCZvaA3CosV5lqyv6dkeMpVQJANVSRT8hNRpnMM9RagVTftDhDI2sBNEhRh8IrSIqN2ZMh9mZ6C7gHwXcA2MimTTe+NzZba1E7apmhe1cwwskqwg==");
                    zfrygl.put("createTime","2020-05-14T08:08:22.000+0000");
                    zfrygl.put("appId","f004d1e110ed40d1a19d18c2ccbc3c0b");
                    zfrygl.put("createUser","c8f1ba6c7cf842409aba43206e9f7442");
                }
            }
        }
        if (zfrygl != null && !zfrygl.isEmpty()){
            sysApp.add(zfrygl);
        }
        for (int i = 0; i < sysApp1.size(); i++) {
            Map<String,Object> map = sysApp1.get(i);
            if ("执法监管".equals(map.get("appName"))){
                sysApp.add(map);
            }
        }
        for (int i = 0; i < sysApp1.size(); i++) {
            Map<String,Object> map = sysApp1.get(i);
            if ("风险预警".equals(map.get("appName"))){
                sysApp.add(map);
            }
        }
        for (int i = 0; i < sysApp1.size(); i++) {
            Map<String,Object> map = sysApp1.get(i);
            if ("综合分析".equals(map.get("appName"))){
                sysApp.add(map);
            }
        }
        for (int i = 0; i < sysApp1.size(); i++) {
            Map<String,Object> map = sysApp1.get(i);
            if ("地震安全性评价与抗震设防要求监管".equals(map.get("appName"))){
                sysApp.add(map);
            }
        }
        for (int i = 0; i < sysApp1.size(); i++) {
            Map<String,Object> map = sysApp1.get(i);
            if ("地震监测设施监管".equals(map.get("appName"))){
                sysApp.add(map);
            }
        }
        for (int i = 0; i < sysApp1.size(); i++) {
            Map<String,Object> map = sysApp1.get(i);
            if ("外国组织或者个人在华从事地震监测活动监管".equals(map.get("appName"))){
                sysApp.add(map);
            }
        }
        for (int i = 0; i < sysApp1.size(); i++) {
            Map<String,Object> map = sysApp1.get(i);
            if ("防震减灾知识宣传教育工作监管".equals(map.get("appName"))){
                sysApp.add(map);
            }
        }
        for (int i = 0; i < sysApp1.size(); i++) {
            Map<String,Object> map = sysApp1.get(i);
            if ("擅自公告震后地震趋势监管".equals(map.get("appName"))){
                sysApp.add(map);
            }
        }
        return R.ok().put("data",sysApp);
    }
    /*public  List<Map<String,Object>> getMenu(LoginUser userInfo,String appCode) {
        String id = userInfo.getUserId();
        // 根据用户id和子系统code获取菜单信息
        String url = BASE_URL + "/platform/api/sys/menus/userid/" + id + "/appcode/" + appCode;
        Map<String, String> map = new HashMap<>();
        HttpMethod method = HttpMethod.GET;
        Map body = RestfulUtil.sendRestful(request, map, url, method);
        String data = JSONObject.toJSONString(body.get("data"));
        JSONArray result = JSONArray.parseArray(data);
        List<Map<String,Object>> meuList = (List<Map<String, Object>>) JSONArray.parse(data);
        return meuList;
    }*/
}
